//按钮事件新增或编辑
var BFADBC_type = "";
//其他页面传到本页面参数
var BFADBC_param = {};
//暂时没用
var BFADBC_validate = "";
//当前触发按钮
var BFADBC_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var BFADBC_ary_S_STATE = [{"MAIN_ID":"1","CN_NAME":"启用"},{"MAIN_ID":"0","CN_NAME":"禁用"}];

/*declare select options end*/

//输入框默认值
function BFADBC_input_default(){
	/*时间格式初始化*/
	/*form datetime init begin*/
    if($("#BFADBC_CREATE_DATE").val() == "")
    {
        $("#BFADBC_CREATE_DATE").val(new Date().Format('yyyy-MM-dd hh:mm:ss'));
    }
    laydate.render({
        elem: '#BFADBC_CREATE_DATE',
        type: 'datetime',
        trigger: 'click'
    });
	
    /*form datetime init end*/
	//所有输入框设置默认值
	/*Input Default Begin*/
	$("#BFADBC_S_STATE").val('1');
	$("#BFADBC_S_SORT").val('0');
	/*Input Default End*/
}

//主从表传递参数
function BFADBC_param_set(){
	/*Main Subsuv Table Param Begin*/
	if(BFADBC_param.hasOwnProperty("P_CODE"))
 		$("#BFADBC_P_CODE").val(BFADBC_param["P_CODE"]);
	if(BFADBC_param.hasOwnProperty("P_CODE_cn_name"))
       $("#BFADBC_P_CODE_cn_name").val(BFADBC_param["P_CODE_cn_name"]);
	
	/*Main Subsuv Table Param end*/
   	/*父页面查询条件参数传递至子页面并赋值*/
	/*Get Find Select param bgein*/
	if(BFADBC_param.hasOwnProperty("AREA_CODE"))
   	$("#BFADBC_AREA_CODE").val(BFADBC_param["AREA_CODE"]);
	if(BFADBC_param.hasOwnProperty("AREA_NAME"))
   	$("#BFADBC_AREA_NAME").val(BFADBC_param["AREA_NAME"]);
	
	/*Get Find Select param end*/	
}

//业务逻辑数据开始
function BFADBC_t_code_regions_biz_start(inputdata) {
	BFADBC_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    $.each(BFADBC_ary_S_STATE, function (i, obj) {
        addOptionValue("BFADBC_S_STATE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
    });
    BFADBC_init_t_code_regions()
	
    /*biz end*/
}

/*biz step begin*/
function BFADBC_format_S_STATE(value, row, index) {
    var objResult = value;
    for(i = 0; i < BFADBC_ary_S_STATE.length; i++) {
        var obj = BFADBC_ary_S_STATE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}


/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function BFADBC_page_end(){
	if(BFADBC_param["type"] == "edit"){
		BFADBC_get_edit_info();
	}
}

//页面初始化方法
function BFADBC_init_t_code_regions() {
	//输入框默认值
	BFADBC_input_default();
	//参数传递
	BFADBC_param_set();	
	//表单验证
	BFADBC_checkFormInput();
	//结束函数
	BFADBC_page_end();
}

//提交表单数据
function BFADBC_SubmitForm(){
	if(BFADBC_param["type"] == "add"){
		var inputdata = {
				"param_name": "N01_ins_t_code_regions",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": s_encode($("#BFADBC_PROVINCE_REGIONS_CODE").val())
                ,"param_value2": s_encode($("#BFADBC_PROVINCE_REGIONS").val())
                ,"param_value3": s_encode($("#BFADBC_CITY_REGIONS_CODE").val())
                ,"param_value4": s_encode($("#BFADBC_CITY_REGIONS").val())
                ,"param_value5": s_encode($("#BFADBC_COUNTY_REGIONS_CODE").val())
                ,"param_value6": s_encode($("#BFADBC_COUNTY_REGIONS").val())
                ,"param_value7": s_encode($("#BFADBC_P_CODE").val())
                ,"param_value8": s_encode($("#BFADBC_AREA_CODE").val())
                ,"param_value9": s_encode($("#BFADBC_AREA_NAME").val())
                ,"param_value10": $("#BFADBC_S_STATE").val()
                ,"param_value11": $("#BFADBC_S_SORT").val()
                ,"param_value12": $("#BFADBC_CREATE_DATE").val()
                ,"param_value13": s_encode($("#BFADBC_S_DESC").val())
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "BFADBC_get_N01_ins_t_code_regions");
	}
	else if(BFADBC_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_t_code_regions",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": s_encode($("#BFADBC_PROVINCE_REGIONS_CODE").val())
                ,"param_value2": s_encode($("#BFADBC_PROVINCE_REGIONS").val())
                ,"param_value3": s_encode($("#BFADBC_CITY_REGIONS_CODE").val())
                ,"param_value4": s_encode($("#BFADBC_CITY_REGIONS").val())
                ,"param_value5": s_encode($("#BFADBC_COUNTY_REGIONS_CODE").val())
                ,"param_value6": s_encode($("#BFADBC_COUNTY_REGIONS").val())
                ,"param_value7": s_encode($("#BFADBC_P_CODE").val())
                ,"param_value8": s_encode($("#BFADBC_AREA_CODE").val())
                ,"param_value9": s_encode($("#BFADBC_AREA_NAME").val())
                ,"param_value10": $("#BFADBC_S_STATE").val()
                ,"param_value11": $("#BFADBC_S_SORT").val()
                ,"param_value12": $("#BFADBC_CREATE_DATE").val()
                ,"param_value13": s_encode($("#BFADBC_S_DESC").val())
                ,"param_value14": $("#BFADBC_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "BFADBC_get_N01_upd_t_code_regions");
	}
}

//vue回调
function BFADBC_t_code_regions_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
}

//for表单提交
$("#BFADBC_save_t_code_regions_Edit").click(function () {
	$("form[name='BFADBC_DataModal']").submit();
})

/*修改数据*/
function BFADBC_get_N01_upd_t_code_regions(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_code_regions) == true)
	{
		swal("修改数据成功!", "", "success");
		AFADBC_t_code_regions_query();
		BFADBC_clear_validate();
		layer.close(BFADBC_param["ly_index"]);
	}
}

/*添加数据*/
function BFADBC_get_N01_ins_t_code_regions(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_code_regions) == true)
	{
		swal("添加数据成功!", "", "success");
		AFADBC_t_code_regions_query();
		BFADBC_clear_validate();
		layer.close(BFADBC_param["ly_index"]);
	}
}

//取消编辑
$("#BFADBC_cancel_t_code_regions_Edit").click(function () {
	layer.close(BFADBC_param["ly_index"]);
	BFADBC_clear_validate();
	$("[id^='BFADBC_div']").hide();
})

//清除查找框
function BFADBC_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function BFADBC_clear_validate(){
	$("#BFADBC_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#BFADBC_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#BFADBC_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function BFADBC_clear_edit_info(){
	var inputs = $("#BFADBC_DataModal").find('input');
	var selects = $("#BFADBC_DataModal").find("select");
	var textareas = $("#BFADBC_DataModal").find('textarea');
	var divs = $("div[id^='BFADBC'][id$='FILE_div']");  
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	$.each(divs, function (i, obj) {
		$(obj).html("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
	
	/*input validate clear end*/
	BFADBC_init_t_code_regions();
}

//页面输入框赋值
function BFADBC_get_edit_info(){
	var rowData = $("#AFADBC_t_code_regions_Events").bootstrapTable('getData')[AFADBC_select_t_code_regions_rowId];
	var inputs = $("#BFADBC_DataModal").find('input');
	var selects = $("#BFADBC_DataModal").find("select");
	var textareas = $("#BFADBC_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"AFADBC","BFADBC");
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function BFADBC_checkFormInput() {
    BFADBC_validate = $("#BFADBC_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            BFADBC_MAIN_ID: {}
            ,BFADBC_PROVINCE_REGIONS_CODE: {maxlength:20}
            ,BFADBC_PROVINCE_REGIONS: {maxlength:50}
            ,BFADBC_CITY_REGIONS_CODE: {maxlength:20}
            ,BFADBC_CITY_REGIONS: {maxlength:50}
            ,BFADBC_COUNTY_REGIONS_CODE: {maxlength:20}
            ,BFADBC_COUNTY_REGIONS: {maxlength:50}
            ,BFADBC_P_CODE: {maxlength:50}
            ,BFADBC_AREA_CODE: {maxlength:20}
            ,BFADBC_AREA_NAME: {maxlength:50}
            ,BFADBC_S_STATE: {}
            ,BFADBC_S_SORT: {digits: true,required : true,maxlength:10}
            ,BFADBC_CREATE_DATE: {date: true,required : true,maxlength:19}
            ,BFADBC_S_DESC: {maxlength:500}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            BFADBC_MAIN_ID: {}
            ,BFADBC_PROVINCE_REGIONS_CODE: {maxlength:"长度不能超过20"}
            ,BFADBC_PROVINCE_REGIONS: {maxlength:"长度不能超过50"}
            ,BFADBC_CITY_REGIONS_CODE: {maxlength:"长度不能超过20"}
            ,BFADBC_CITY_REGIONS: {maxlength:"长度不能超过50"}
            ,BFADBC_COUNTY_REGIONS_CODE: {maxlength:"长度不能超过20"}
            ,BFADBC_COUNTY_REGIONS: {maxlength:"长度不能超过50"}
            ,BFADBC_P_CODE: {maxlength:"长度不能超过50"}
            ,BFADBC_AREA_CODE: {maxlength:"长度不能超过20"}
            ,BFADBC_AREA_NAME: {maxlength:"长度不能超过50"}
            ,BFADBC_S_STATE: {}
            ,BFADBC_S_SORT: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,BFADBC_CREATE_DATE: {date: "必须输入正确格式的日期",required : "必须输入正确格式的日期",maxlength:"长度不能超过19"}
            ,BFADBC_S_DESC: {maxlength:"长度不能超过500"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	BFADBC_SubmitForm();
        	return false;
        }
    })
}